package com.itheima.controller;


import com.itheima.common.R;
import com.itheima.domain.User;
import com.itheima.domain.vo.UserVo;
import com.itheima.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private UserService userServicer;


    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;


    @PostMapping("/login")
    public R<UserVo> userLogin(@RequestBody Map map) {
        log.info("前端传的用户手机号和验证码 map={}", map);
        return userServicer.clientUserLogin(map);

    }

    /**
     *
     * @param user 用户对象封装的用户手机号
     * @return 发送结果
     */
    @PostMapping("/sendMsg")
    public R<String> sendmessage(@RequestBody User user) {
        log.info("用户对象封装的用户手机号 user={}", user);
        return userServicer.clientSendmessage(user);
    }


    /**
     * 后管登出
     *
     * @return 登出结果
     */
    @PostMapping("/logout")
    public R<String> loginOut(@RequestHeader("AuthorizationUser") String token) {
        log.info("删除redis数据库中的token={}", token);
        return userServicer.clientLoginOut(token);
    }


}
